<!--
***********************************************************************************************
Microsoft.NETCore.Native.Windows.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

This file defines Windows-specific steps in the build process for native AOT compilation.

Licensed to the .NET Foundation under one or more agreements.
The .NET Foundation licenses this file to you under the MIT license.
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <CppLinker>link</CppLinker>
    <CppLibCreator>lib</CppLibCreator>
    <ObjectSuffix>.obj</ObjectSuffix>
    <LibrarySuffix>.lib</LibrarySuffix>
    <ObjectSuffix Condition="'$(ControlFlowGuard)' == 'Guard'">.GuardCF.obj</ObjectSuffix>
    <LibrarySuffix Condition="'$(ControlFlowGuard)' == 'Guard'">.GuardCF.lib</LibrarySuffix>
    <FullRuntimeName>Runtime.WorkstationGC</FullRuntimeName>
    <FullRuntimeName Condition="'$(ServerGarbageCollection)' == 'true' or '$(ControlFlowGuard)' == 'Guard'">Runtime.ServerGC</FullRuntimeName>
    <BootstrapperName>bootstrapper</BootstrapperName>
    <BootstrapperName Condition="'$(NativeLib)' != '' or '$(CustomNativeMain)' == 'true'">bootstrapperdll</BootstrapperName>
    <VxSortSupportName>Runtime.VxsortEnabled</VxSortSupportName>
    <VxSortSupportName Condition="'$(ControlFlowGuard)' != 'Guard' and ('$(OptimizationPreference)' == 'Size' or '$(IlcDisableVxsort)' == 'true')">Runtime.VxsortDisabled</VxSortSupportName>
    <StandaloneGCSupportName>standalonegc-disabled</StandaloneGCSupportName>
    <StandaloneGCSupportName Condition="'$(IlcStandaloneGCSupport)' == 'true'">standalonegc-enabled</StandaloneGCSupportName>
    <EntryPointSymbol Condition="'$(EntryPointSymbol)' == ''">wmainCRTStartup</EntryPointSymbol>
    <LinkerSubsystem Condition="'$(OutputType)' == 'WinExe' and '$(LinkerSubsystem)' == ''">WINDOWS</LinkerSubsystem>
    <LinkerSubsystem Condition="'$(OutputType)' == 'Exe' and '$(LinkerSubsystem)' == ''">CONSOLE</LinkerSubsystem>
    <EventPipeName>eventpipe-disabled</EventPipeName>
    <EventPipeName Condition="'$(EventSourceSupport)' == 'true'">eventpipe-enabled</EventPipeName>
    <IlcDefaultStackSize Condition="'$(IlcDefaultStackSize)' == ''">1572864</IlcDefaultStackSize>
  </PropertyGroup>

  <!-- Ensure that runtime-specific paths have already been set -->
  <Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">

    <ItemGroup>
      <NativeLibrary Include="$(IlcSdkPath)$(BootstrapperName)$(ObjectSuffix)" />
      <NativeLibrary Include="$(IlcSdkPath)$(FullRuntimeName)$(LibrarySuffix)" />
      <NativeLibrary Include="$(IlcSdkPath)$(EventPipeName)$(LibrarySuffix)" />
      <NativeLibrary Condition="'$(_targetArchitecture)' == 'x64'" Include="$(IlcSdkPath)$(VxSortSupportName)$(LibrarySuffix)" />
      <NativeLibrary Condition="'$(IlcMultiModule)' == 'true'" Include="$(SharedLibrary)" />
      <NativeLibrary Include="$(IlcSdkPath)$(StandaloneGCSupportName)$(LibrarySuffix)" />
    </ItemGroup>

    <ItemGroup>
      <NetCoreAppNativeLibrary Include="System.Globalization.Native" />
      <NetCoreAppNativeLibrary Include="System.IO.Compression.Native" />
    </ItemGroup>

    <ItemGroup>
      <DirectPInvoke Include="@(NetCoreAppNativeLibrary->'%(Identity)')" />
      <NetCoreAppNativeLibrary Include="@(NetCoreAppNativeLibrary->'%(Identity)')">
        <EscapedPath>$(IlcSdkPath)%(Identity).Aot$(LibrarySuffix)</EscapedPath>
      </NetCoreAppNativeLibrary>
      <NativeLibrary Include="@(NetCoreAppNativeLibrary->'%(EscapedPath)')" />
    </ItemGroup>

    <ItemGroup>
      <SdkNativeLibrary Include="advapi32.lib" />
      <SdkNativeLibrary Include="bcrypt.lib" />
      <SdkNativeLibrary Include="crypt32.lib" />
      <SdkNativeLibrary Include="iphlpapi.lib" />
      <SdkNativeLibrary Include="kernel32.lib" />
      <SdkNativeLibrary Include="mswsock.lib" />
      <SdkNativeLibrary Include="ncrypt.lib" />
      <SdkNativeLibrary Include="normaliz.lib" />
      <SdkNativeLibrary Include="ntdll.lib" />
      <SdkNativeLibrary Include="ole32.lib" />
      <SdkNativeLibrary Include="oleaut32.lib" />
      <SdkNativeLibrary Include="secur32.lib" />
      <SdkNativeLibrary Include="user32.lib" />
      <SdkNativeLibrary Include="version.lib" />
      <SdkNativeLibrary Include="ws2_32.lib" />
    </ItemGroup>

    <ItemGroup>
      <DirectPInvokeList Include="$(MSBuildThisFileDirectory)WindowsAPIs.txt" />
    </ItemGroup>

    <ItemGroup>
      <LinkerArg Condition="'$(NativeLib)' == 'Shared'" Include="/DLL" />
      <LinkerArg Include="@(NativeLibrary->'&quot;%(Identity)&quot;')" />
      <LinkerArg Include="@(SdkNativeLibrary->'&quot;%(Identity)&quot;')" />
      <LinkerArg Include="/NOLOGO /MANIFEST:NO" />
      <LinkerArg Condition="$(NativeDebugSymbols) == 'true'" Include="/DEBUG" />
      <!-- The runtime is not compatible with jump stubs inserted by incremental linking. -->
      <LinkerArg Include="/INCREMENTAL:NO" />
      <LinkerArg Condition="'$(LinkerSubsystem)' != ''" Include="/SUBSYSTEM:$(LinkerSubsystem)" />
      <LinkerArg Condition="'$(OutputType)' == 'WinExe' or '$(OutputType)' == 'Exe'" Include="/ENTRY:$(EntryPointSymbol) /NOEXP /NOIMPLIB" />
      <LinkerArg Include="/NATVIS:&quot;$(MSBuildThisFileDirectory)NativeAOT.natvis&quot;" />
      <LinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
      <LinkerArg Condition="'$(OutputType)' == 'WinExe' or '$(OutputType)' == 'Exe'" Include="/STACK:$(IlcDefaultStackSize)" />
      <!-- Do not warn if someone declares UnmanagedCallersOnly with an entrypoint of 'DllGetClassObject' and similar -->
      <LinkerArg Include="/IGNORE:4104" />
    </ItemGroup>

    <ItemGroup Condition="!Exists('$(IlcSdkPath)debugucrt.txt')">
      <!-- Force ucrt to be dynamically linked for release runtime -->
      <LinkerArg Include="/NODEFAULTLIB:libucrt.lib" />
      <LinkerArg Include="/DEFAULTLIB:ucrt.lib" />
    </ItemGroup>

    <ItemGroup Condition="'$(Configuration)' != 'Debug'">
      <LinkerArg Include="/OPT:REF" />
      <LinkerArg Include="/OPT:ICF" />
    </ItemGroup>

    <Exec Condition="'$(IlcUseEnvironmentalTools)' != 'true'" Command="&quot;$(MSBuildThisFileDirectory)findvcvarsall.bat&quot; $(_targetArchitecture)"
      IgnoreExitCode="true" ConsoleToMSBuild="true" StandardOutputImportance="Low">
      <Output TaskParameter="ConsoleOutput" PropertyName="_FindVCVarsallOutput" />
      <Output TaskParameter="ExitCode" PropertyName="_VCVarsAllFound" />
    </Exec>

    <ItemGroup Condition="'$(_VCVarsAllFound)' == '0'">
      <AdditionalNativeLibraryDirectories Include="$(_FindVCVarsallOutput.Split(`#`)[1].Split(';'))" />
    </ItemGroup>

    <PropertyGroup Condition="'$(_VCVarsAllFound)' == '0'">
      <_CppToolsDirectory>$(_FindVCVarsallOutput.Split(`#`)[0])</_CppToolsDirectory>
      <CppLinker>$(_CppToolsDirectory)link.exe</CppLinker>
      <CppLibCreator>$(_CppToolsDirectory)lib.exe</CppLibCreator>
    </PropertyGroup>

    <Error Condition="'$(_VCVarsAllFound)' == '1'" Text="Platform linker not found. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites, in particular the Desktop Development for C++ workload in Visual Studio. For ARM64 development also install C++ ARM64 build tools." />
  </Target>
</Project>
